<?php

namespace App\Http\Controllers\home;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;
class OkconfirmController extends Controller
{
     public function index()
    {
      //查询数据库数据显示确认收货页面信息
       $ss=DB::table('product')->inRandomOrder()->take(6)->get()->all();
         $type=DB::table('type')->get()->all();
        $id=session('homeuser')->id;
        $result= DB::table('myorder')->where('user_id',$id)->first();
           $links=DB::table('links')->get();
        if(!empty($result)){
        // $okconfirm = DB::table('user')
        //   ->join('myorder', 'user.id', '=', 'myorder.user_id')
        //   ->join('product', 'myorder.product_id', '=', 'product.id')
        //   ->select('product.*', 'myorder.status', 'myorder.order_time')
        //   ->where('myorder.user_id','=',$id)
        //   ->orderBy('myorder.order_time', 'desc');

        $okconfirm = DB::table('myorder')
        ->leftjoin('product', 'myorder.product_id', '=', 'product.id')
        ->where('myorder.user_id','=',$id)
        ->where('myorder.status','=','3')
        ->select('myorder.*','product.name')
        ->get();

    
  // $okconfirm = DB::select( 'select * from `myorder` left join `product` on `myorder`.`product_id` = `product`.`id` where `myorder`.`user_id` = '.$id);

        return view('home.okconfirm',['okconfirm'=>$okconfirm,'links'=>$links,'search'=>$ss,
         'all'=>$type]);
      }else{
          return view('home.okconfirm',['links'=>$links,'search'=>$ss,
         'all'=>$type]);
        }  
    }

     public function dookconfirm(Request $request){
       //AJAX返回获取到订单表的信息数据
        $id = $request->input('id');
          // dd($id);
        $db=DB::table('myorder')->where('id',$id)->update(['status'=>4]);
        if($db>0){
        echo json_encode($db);
        }
    }


}
